const utils = require('j7/utils');
const BaseModel = require('./basemodel');

class Transaction extends BaseModel {

  async add(account, data, netId) {
    const result = {
      err: null,
      seqId: 0
    };
    const nowTime = utils.getUtcTime();
    const lastId = await this.getSession().bcEventConn
    (
      'insertEx',
      't_transaction',
      [
        ['account', account],
        ['data', data],
        ['net_id', netId],
        ['createtime', nowTime],
        ['modifytime', nowTime],
      ]
    );
    result['seqId'] = lastId;
    return result;
  }

  async update(idx, fields) {
    const err = await this.getSession().bcEventConn
    (
      'update',
      't_transaction',
      [
        ['idx', idx]
      ],
      fields
    );
    return err;
  }

}

module.exports = Transaction;
